import React from "react";
import {BrowserRouter} from "react-router-dom";
import Layout from "../component/Layout";
import Context from "./Context";
import Main from "./Main";
import Side from "./Side";

export default class App extends React.Component
{
    constructor (props, context, updater)
    {
        super (props, context, updater);
        this.state = {showSide:true};
    }

    /**
     * 处理左侧菜单显示
     */
    handleIndent = () =>
    {
        this.setState({showSide:!this.state.showSide});
    };

    /**
     * 处理刷新
     */
    handleRefresh = () =>
    {
        alert("页面刷新");
    };

    /**
     * 网站首页
     */
    handleIndex = () =>
    {

    };

    /**
     * 返回上下文
     */
    handleContext = () =>
    {
        return {
            showSide: this.state.showSide,
            handleIndent : this.handleIndent,
            handleIndex : this.handleIndex,
            handleRefresh : this.handleRefresh
        };
    };

    render ()
    {
        return <BrowserRouter>
            <Context.Provider value={this.handleContext()}>
            <Layout.Horizontal style={{flexShrink:0}}>
                <Side/>
                <Main/>
            </Layout.Horizontal>
            </Context.Provider>
        </BrowserRouter>
    }
}